﻿using NUnit.Framework;
using Pyxis.FluentSelenium.Conditions;
using Pyxis.FluentSelenium.Locator;
using Selenium;

namespace Pyxis.FluentSelenium.SampleWebAppTest.SimpleExamples
{
    [TestFixture]
    public class AutoPostBackDropDownListTest
    {
        private WebApplication application;
        private User user;

        private static readonly PageLoadWaitCondition autoPostBackDropDownListPage = new PageLoadWaitCondition("SimpleExamples/autoPostBackDropDownListPage.aspx");
        private static readonly ComboboxLocator colorComboBox = ComboboxLocator.WithId("ddlColor", autoPostBackDropDownListPage);
        private static readonly ElementLocator labelSelectedColor = ElementLocator.WithId("lblSelectedColor");

        [SetUp]
        public void Setup()
        {
            application = new WebApplication(3000, "Pyxis.FluentSelenium.SampleWebApp");
            application.Start();

            var selenium = new DefaultSelenium("127.0.0.1", 4445, "*iexplore", "http://localhost:3000/");
            user = new User(selenium);
            user.Start();
        }

        [TearDown]
        public void TearDown()
        {
            user.Stop();
            application.Stop();
        }

        [Test]
        public void TestAutoPostBackDropDownWithWaitConditionIncludedInLocator()
        {
            user.Goto("SimpleExamples/autoPostBackDropDownListPage.aspx");

            user.For(colorComboBox).Selects("Blue");
            user.For(labelSelectedColor).ShouldSee("Blue");
        }

        [Test]
        public void TestDropDownListContainsAllOptions()
        {
            user.Goto("SimpleExamples/autoPostBackDropDownListPage.aspx");

            user.For(colorComboBox).ShouldSeeOptions("White", "Blue", "Red", "Yellow");
        }
    }
}
